package com.java.lang;
/**
 * 性能优化
 * @author Administrator
 *
 */
public class Calc {
	private static final int VALUE=100000;
	public static void main(String[] args) {
//		calc1();
//		calc2();
		calcStr1();
		calcStr2();
	}

	private static void calc1() {
		long time1 = System.currentTimeMillis();
		Long sum = 0l;
		for (long i = 0; i < Integer.MAX_VALUE/3; i++) {
			sum += i;
		}
		long time2 = System.currentTimeMillis();
		System.out.println(time2 - time1);
	}
	private static void calc2() {
		long time1 = System.currentTimeMillis();
		long sum = 0l;
		for (long i = 0; i < Integer.MAX_VALUE/3; i++) {
			sum += i;
		}
		long time2 = System.currentTimeMillis();
		System.out.println(time2 - time1);
	}
	
	
	private static void calcStr1() {
		long time1 = System.currentTimeMillis();
		String sum ="";
		for (long i = 0; i < VALUE; i++) {
			sum += i;
		}
		long time2 = System.currentTimeMillis();
		System.out.println(time2 - time1);
	}
	
	private static void calcStr2() {
		long time1 = System.currentTimeMillis();
		StringBuilder sum =new StringBuilder();
		for (long i = 0; i < VALUE; i++) {
			sum.append(i);
		}
		long time2 = System.currentTimeMillis();
		System.out.println(time2 - time1);
	}
}
